package com.example.jsruntimedemo;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

import com.example.jsruntimedemo.js.JsApplication;
import com.example.jsruntimedemo.js.JsBundle;

public class MainActivity extends AppCompatActivity {
    private static final String TAG = "MainActivity";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        JsBundle jsBundle=new JsBundle();
        jsBundle.setAppJavaScript("const hello = \"Hello \";\n" +
                "const title = hello + \"Hybrid World!\"\n" +
                "console.info(\"start!\")\n" +
                "$view.render({\n" +
                "    rootView: {\n" +
                "        type: \"verticalLayout\",\n" +
                "        children: [\n" +
                "            {\n" +
                "                \"type\": \"text\",\n" +
                "                \"text\": title,\n" +
                "                \"textSize\": 24,\n" +
                "                \"marginTop\": 16\n" +
                "            },\n" +
                "            {\n" +
                "                \"type\": \"image\",\n" +
                "                \"width\": 72,\n" +
                "                \"height\": 72,\n" +
                "                \"marginTop\": 80,\n" +
                "                \"url\": \"\"\n" +
                "            },\n" +
                "            {\n" +
                "                \"type\": \"button\",\n" +
                "                \"text\": \"点击打印日志\",\n" +
                "                \"marginTop\": 80,\n" +
                "                \"marginLeft\": 40,\n" +
                "                \"marginRight\": 40,\n" +
                "                \"onClick\": function () {\n" +
                "                    console.info(\"success!\")\n" +
                "                }\n" +
                "            }\n" +
                "        ]\n" +
                "    }\n" +
                "})\n" );
  //      jsBundle.setAppJavaScript("console.info('hello wolrd!')");

        JsApplication jsApplication=JsApplication.init(this,findViewById(R.id.root));
        jsApplication.run(jsBundle);
    //    Log.d(TAG, "result: "+result);
    }
}